using UnityEngine;

namespace Flaschengeist.Processes  
{
	public class CameraZoomOut : MonoBehaviour
	{
		private bool isActive;
		
		public void Process()
		{
			isActive = true;
		}
		
		public void Update()
		{		
			if (isActive)
			{
				isActive = false;
				
				if(zoomOut())
				{
					if(gameObject.transform.position.x > Settings.CAMERA_BORDER_LEFT)		
					{				
						gameObject.transform.position += new Vector3(-0.1f * Settings.CAMERA_ZOOM_SPEED, 0.0f, 0.0f);	
						isActive = true;
					}
				}
				else
				{
					isActive = true;
				}	
			}	
		}
		
		private bool zoomOut()
		{
			bool finished = true;
			
			if(gameObject.transform.position.z > -5)		
			{				
				gameObject.transform.position += new Vector3(0.0f, 0.0f, -0.05f * Settings.CAMERA_ZOOM_SPEED);	
				finished = false;
			}
			
			if(gameObject.transform.position.y < 2.7)
			{
				gameObject.transform.position += new Vector3(0.0f, 0.013f * Settings.CAMERA_ZOOM_SPEED, 0.0f);
				finished = false;
			}	
			
			return finished;
		}
	}
}

